//
//  HomeFamilyView.m
//  Ginix
//
//  Created by 冯志强 on 2025/2/27.
//

#import "HomeFamilyView.h"
#import "HomeFamilyCell.h"

@interface HomeFamilyView()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong) UICollectionView * listView;

@end

@implementation HomeFamilyView

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setSubViewLayout];
    }
    return self;
    
}

-(void)setSubViewLayout{
    
    
    [self addSubview:self.listView];
    [_listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0);
    }];
    
    [self.listView selectItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionNone];
}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 5;
}

-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    HomeFamilyCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeFamilyCell" forIndexPath:indexPath];
    [cell setIndex:indexPath.row];

    return cell;
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{

    return UIEdgeInsetsMake(10* FMScaleX, 20* FMScaleX, 10* FMScaleX, 20* FMScaleX);
}

-(UICollectionView *)listView{

    if (!_listView) {
        UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
        layout.minimumLineSpacing = 20 * FMScaleX;
        layout.minimumInteritemSpacing = 20 * FMScaleX;
        layout.itemSize = CGSizeMake(50 * FMScaleX, 70 * FMScaleX);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

        _listView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
        _listView.delegate = self;
        _listView.dataSource = self;
        _listView.backgroundColor = UIColor.clearColor;
        _listView.showsVerticalScrollIndicator = NO;
        _listView.showsHorizontalScrollIndicator = NO;
        [_listView registerClass:[HomeFamilyCell class] forCellWithReuseIdentifier:@"HomeFamilyCell"];
    }
    return _listView;
}
@end
